/**
 * 轨迹回放公共调用页面
 */
$(function(){
	Map.init();
});

var Map = {
	param: {},
	init: function(){
		var me = this;
		var vehicleId = me.getQueryString("vehicleId");
		if(vehicleId==null||vehicleId=='null'||vehicleId==''){
			TrackMap.init();
			return;
		}else{
			me.queryTrack();
		}
	},
	queryTrack: function(){
		var me = this;
		var vehicleId = me.getQueryString("vehicleId");
		var startTime = me.getQueryString("startTime");
		var endTime = me.getQueryString("endTime");
		
  		$.ajax({
    		type : 'post',
    		async : false,
    		url : appCtx+'gis/playback/queryTrackList.html?vehicleId='+vehicleId+"&startTime="+startTime+"&endTime="+endTime,
    		cache : false,
    		dataType : "JSON",
    		data:{},
    		success : function(data) {			
    			if(data){
    				var lnglatArr = new Array();
    				for(var i=0;i<data.length;i++){
    					var lng = data[i].longitude;
    					var lat = data[i].latitude;
    					var lnglat = new Array();
        				lnglat.push(lng);
        				lnglat.push(lat);
        				lnglatArr.push(lnglat);
    				}
    				var carPic = me.getVehicleStatusPicUrl(0);//TODO 无法获取车辆类型，暂时先取0
    				TrackMap.initMapNoMarker(carPic,lnglatArr);
    			}
    		}
    	});
	},
	/*车辆图标*/
    getVehicleStatusPicUrl : function(status){
        var carStatus = ['car','car','carYellow','red','gray'];
        var picUrl = global.url.domain + "gps-web/resources/images/mapTool/";
        try{
            picUrl += (carStatus[status])+"1.png";
            return picUrl;
        }catch(ex){
            console.log(ex);
            return picUrl  = global.url.domain + "gps-web/resources/images/mapTool/car1.png";  //出错的话 默认车辆图标
        }
    },
	//获取url的参数
	getQueryString: function (name) { 
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
        var r = window.location.search.substr(1).match(reg); 
        if (r != null) return unescape(r[2]); 
        return null; 
    }
};


